<?php
defined('IN_PHPCMS') or exit('No permission resources.'); 
/**
 * 短信发送接口
 */
 $mobile = $_GET['mobile'];
$siteid = get_siteid() ? get_siteid() : 1 ;
$sitelist = getcache('sitelist', 'commons');
$sitename = $sitelist[$siteid]['name'];
if(!preg_match('/^(?:13\d{9}|15[0|1|2|3|5|6|7|8|9]\d{8}|18[0|2|3|5|6|7|8|9]\d{8}|14[5|7]\d{8})$/',$mobile)) exit('mobile phone error');
//查询帐号
$member_db = pc_base::load_model('member_model');
$r = $member_db->get_one(array('username'=>$mobile));
if(!$r){
	$userinfo = array();
	$userinfo['username'] = $mobile;
	$userinfo['mobile'] = $mobile;
	$userinfo['code'] = mt_rand(1000,9999);
	//$userinfo['code'] = 1234;
	$userinfo['email'] = $userinfo['username'].'@appbaba.com';
	$userinfo['password'] = '123456';
	$userinfo['encrypt'] = create_randomstr(6);
	$userinfo['modelid'] = 10;
	$userinfo['groupid'] = 2;
	$userinfo['regip'] = ip();
	$userinfo['islock'] = 0;
	$userinfo['point'] = $member_setting['defualtpoint'] ? $member_setting['defualtpoint'] : 0;
	$userinfo['amount'] = $member_setting['defualtamount'] ? $member_setting['defualtamount'] : 0;
	$userinfo['regdate'] = $userinfo['lastdate'] = SYS_TIME;
	$userinfo['siteid'] = 1;
	
	$userinfo['password'] = password($userinfo['password'], $userinfo['encrypt']);
	$userid = $member_db->insert($userinfo, 1);
}
$id_code = $r['code'] ?  $r['code']: $userinfo['code'];


$send_txt = '尊敬的会员，您在'.$sitename.'的验证码为："'.$id_code.'"。';
$result = file_get_contents('http://service.winic.org/sys_port/gateway/?id=cbxboy&pwd=cbx8869725&to='.$mobile.'&content='.iconv('UTF-8', 'GB2312', $send_txt).'&time=');
$resultarr =explode('/',$result);
if ($resultarr[0]==000){
	echo 0;
	$sms_db = pc_base::load_model('sms_model');
	$data = array('mobile' => $mobile,'posttime' => SYS_TIME,'id_code' => $id_code,'msg' => $send_txt,'status' => 1);
	$sms_db->insert($data);
}else{
	echo $result;
}
 
/// echo 0;
?>